function [lpostd,flag_ok]= lmj_postoptim_central(parest, parvec, parposest, indmat, funcmod, Y, trainvec, prpar, prss, solveopt, addsol, ssposest, flag_transform)
% ======================================================================
% LMJ_POSTOPTMIN_CENTRAL.M
% CENTRAL since it allows for time aggregation issues, using same set-up as
% LMJ_LIKEL_CENTRAL.m 
%
% [lpostd,flag_ok]= lmj_postoptim_central(parest, parvec, parposest,
% indmat, funcmod, Y, trainvec, prpar, prss, solveopt, addsol, ssposest, flag_transform)
%
% LPOSTD        == 1e20 if there are problems 
% FLAG_OK       ==0 if there are problems 
%               Different from FLAG_LIKELOK, from all likelihood
%               optimization routines 
%
% Follows the structure of GENSYSPOST_VEC by Alejandro Justiniano (C)
% IN addition to putting priors on parameters, our current model put
% priors on steady state values.
%
% LIKEL: Default value for problems is 1e40 
% =======================================================================
lpostd=1e20;flag_ok=0;
% 1. Transform to go from MIN to MOD
% ----------------------------------
if flag_transform ==1
    parest=feval(@min2mod,parest,indmat);
    %[parest,flag_c]=feval(@check_min,parest,indmat);
    %if flag_c==0;disp('Problems with transformed coefficients');return;end
end
%disp('Adding PAREST to PARVEC'); 
parvec(parposest)=parest; 
switch addsol.flag_mixfreq
    case 0
           [likel, ssvec,flag_likelok]= feval(@lmj_likel,parest, parvec, parposest, funcmod, Y, trainvec,solveopt, addsol);
    case 1
        if addsol.flag_gtv == 1
            [likel, ssvec,flag_likelok]=feval(@lmj_likel_tagtv_general,parest, parvec, parposest, funcmod, Y, trainvec, solveopt, addsol);
        else
            [likel, ssvec,flag_likelok]=feval(@lmj_likel_tagin,parest, parvec, parposest, funcmod, Y, trainvec, solveopt, addsol);
        end
end
if flag_likelok==0;  
    return
end
if isinf(abs(likel));
    disp('Likelihood is infinite!')
    return
end
%% Prior Density of Parameters
lpriord=sum(feval(@priordens,parvec, prpar.prior, prpar.alphap, prpar.betap, prpar.lbnd, prpar.ubnd));
if isinf(abs(lpriord))==1;return;end
%% Prior Density on Steady State
if ~isempty(ssposest)
    lpriord_ss = sum(feval(@priordens,ssvec(ssposest), prss.prior, prss.alphap, prss.betap, prss.lbnd, prss.ubnd));
else
    lpriord_ss=0;
end
if isinf(abs(lpriord_ss))==1;return;end
%% log likelihood
lpostd = -(lpriord + lpriord_ss + likel);
flag_ok=1; 